home *** CD-ROM | disk | FTP | other *** search
/ PC Format (PL) 2008 December / PC_Format_122008.iso / Multimedia / MediaPortal 0.2.3.0 / MediaPortal_0.2.3.0_Setup.exe / scripts / imdb / movdb.csscript < prev    next >
Text File  |  2007-08-20  |  6KB  |  199 lines

  1. //css_reference "core.dll";
  2. //css_reference "Databases.dll";
  3. //css_reference "utils.dll";
  4.  
  5. using System;
  6. using System.Collections.Generic;
  7. using System.ComponentModel;
  8. using System.Data;
  9. using System.Drawing;
  10. using System.Text;
  11. using System.Windows.Forms;
  12. using System.IO;
  13. using System.Net;
  14. using System.Collections;
  15. using System.Web;
  16. using System.Xml;
  17. using System.Text.RegularExpressions;
  18. using MediaPortal.Util;
  19.  
  20. // change to Grabber, this for avoid to load by mediaportal
  21. class Grabber : MediaPortal.Video.Database.IIMDBScriptGrabber
  22. {
  23.   public Grabber()
  24.   {
  25.   }
  26.  
  27.   void MediaPortal.Video.Database.IIMDBScriptGrabber.FindFilm(string strSearch, int iLimit, ArrayList elements)
  28.   {
  29.     string strURL = "http://www.movie-xml.com/xml/GetSeries.php?searchby=SeriesName&string=" + strSearch;
  30.     string title = "";
  31.     string databaseurl = "";
  32.     // string absoluteUri;
  33.     XmlNodeList xmldata = Generic(strURL);
  34.     foreach (XmlNode itemNode in xmldata)
  35.     {
  36.       databaseurl = "http://www.movie-xml.com/xml/GetSeries.php?searchby=id&string=";
  37.       foreach (XmlNode propertyNode in itemNode.ChildNodes)
  38.       {
  39.         if (propertyNode.Name.ToString() == "SeriesName")
  40.           title = propertyNode.InnerText;
  41.         if (propertyNode.Name.ToString() == "id")
  42.           databaseurl += propertyNode.InnerText;
  43.       }
  44.       if (title != "")
  45.       {
  46.         MediaPortal.Video.Database.IMDB.IMDBUrl url = new MediaPortal.Video.Database.IMDB.IMDBUrl(databaseurl, title + " (movdb)", "movdb");
  47.         elements.Add(url);
  48.       }
  49.     }
  50.     // code for search for movie titles  
  51.     // .............
  52.     //.............
  53.     // if movie found add to listing 
  54.   }
  55.  
  56.  
  57.   bool MediaPortal.Video.Database.IIMDBScriptGrabber.GetDetails(MediaPortal.Video.Database.IMDB.IMDBUrl url, ref MediaPortal.Video.Database.IMDBMovie movieDetails)
  58.   {
  59.     // string absoluteUri;
  60.     movieDetails.Title = "";
  61.     XmlNodeList xmldata = Generic(url.URL);
  62.     foreach (XmlNode itemNode in xmldata)
  63.     {
  64.       foreach (XmlNode propertyNode in itemNode.ChildNodes)
  65.       {
  66.         switch (propertyNode.Name.ToString())
  67.         {
  68.           case "SeriesName":
  69.             movieDetails.Title = propertyNode.InnerText;
  70.             break;
  71.           case "SeriesID":
  72.             movieDetails.IMDBNumber = propertyNode.InnerText;
  73.             break;
  74.           case "Yearmade":
  75.             int iYear = 1970;
  76.             System.Int32.TryParse(propertyNode.InnerText, out iYear);
  77.             movieDetails.Year = iYear;
  78.             break;
  79.           case "Director":
  80.             movieDetails.Director = CleanUpSeparator(propertyNode.InnerText).Replace("|", ", ");
  81.             break;
  82.           case "Writer":
  83.             movieDetails.WritingCredits = CleanUpSeparator(propertyNode.InnerText).Replace("|", ", ");
  84.             break;
  85.           case "Genre":
  86.             movieDetails.Genre = CleanUpSeparator(propertyNode.InnerText).Replace("|", " / ");
  87.             break;
  88.           case "Actors":
  89.             movieDetails.Actor =CleanUpSeparator(propertyNode.InnerText).Replace("|", "\n");
  90.             break;
  91.           case "Tagline":
  92.             movieDetails.TagLine = propertyNode.InnerText;
  93.             break;
  94.           case "Overview":
  95.             movieDetails.Plot = propertyNode.InnerText;
  96.             break;
  97.           case "Shortoverview":
  98.             movieDetails.PlotOutline = propertyNode.InnerText;
  99.             break;
  100.           case "Score":
  101.             movieDetails.Votes = propertyNode.InnerText;
  102.             break;
  103.  
  104.         }
  105.       }
  106.     }
  107.  
  108.     XmlNodeList xmldatat = Generic("http://www.movie-xml.com/xml/GetBanners.php?SeriesID=" + movieDetails.IMDBNumber);
  109.  
  110.     foreach (XmlNode itemNode in xmldatat)
  111.     {
  112.  
  113.       foreach (XmlNode propertyNode in itemNode.ChildNodes)
  114.       {
  115.         if (propertyNode.Name.ToString() == "BannerPath")
  116.           movieDetails.ThumbURL = "http://www.movie-xml.com/banners/" + propertyNode.InnerText;
  117.       }
  118.     }
  119.     if (movieDetails.Title == "")
  120.       return false;
  121.     else
  122.       return true;
  123.   }
  124.  
  125.   string MediaPortal.Video.Database.IIMDBScriptGrabber.GetName()
  126.   {
  127.     return "IMDB grabber ";
  128.   }
  129.  
  130.   string MediaPortal.Video.Database.IIMDBScriptGrabber.GetLanguage()
  131.   {
  132.     return "EN";
  133.   }
  134.  
  135.   private string CleanUpSeparator(string strStr)
  136.   {
  137.     if (strStr.StartsWith("|"))
  138.       strStr=strStr.Substring(1);
  139.     if (strStr.EndsWith("|"))
  140.       strStr = strStr.Remove(strStr.Length-1);
  141.     return strStr;
  142.  
  143.   }
  144.   static private XmlNodeList Generic(String sUrl)
  145.   {
  146.     if (sUrl == null || sUrl.Length < 1 || sUrl[0] == '/')
  147.     {
  148.       // this happens if no active mirror is set
  149.       return null;
  150.     }
  151.  
  152.     HttpWebRequest request = null;
  153.     HttpWebResponse response = null;
  154.     Stream data = null;
  155.     try
  156.     {
  157.       request = (HttpWebRequest)WebRequest.Create(sUrl);
  158.       request.Timeout = 20000;
  159.       response = (HttpWebResponse)request.GetResponse();
  160.     }
  161.     catch (Exception e)
  162.     {
  163.       // can't connect, timeout, etc
  164.       MediaPortal.GUI.Library.Log.Error("Can't connect to " + sUrl + " : " + e.Message);
  165.     }
  166.  
  167.     if (response != null)
  168.     {
  169.       // Get the stream associated with the response.
  170.       data = response.GetResponseStream();
  171.       StreamReader reader = new StreamReader(data, Encoding.Default, true);
  172.       String sXmlData = reader.ReadToEnd().Replace('\0', ' ');
  173.       data.Close();
  174.       reader.Close();
  175.       try
  176.       {
  177.         XmlDocument doc = new XmlDocument();
  178.         doc.LoadXml(sXmlData);
  179.         // skip xml node
  180.         XmlNode root = doc.FirstChild.NextSibling;
  181.         if (root.Name == "Items")
  182.         {
  183.           return root.ChildNodes;
  184.         }
  185.       }
  186.       catch (XmlException e)
  187.       {
  188.         // bummer
  189.  
  190.         MediaPortal.GUI.Library.Log.Error("Xml parsing of " + sUrl + " failed (line " + e.LineNumber + " - " + e.Message + ")");
  191.       }
  192.       response.Close();
  193.     }
  194.  
  195.  
  196.     return null;
  197.   }
  198.  
  199. }